import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 报警规则信息 */
export interface AlertRules {
          id: number; // ID
          rule?: string; // 规则
          severity?: string; // 报警级别
          extra?: string; // 附加参数
          disabled?: boolean; // 0启用1禁用
          name?: string; // 规则名称
          query?: string; // 触发条件的 SQL 查询
          builder?: string; // UI 构建的规则结构
          proc: string; // 报警处理函数
          invertMap?: boolean; // 是否反转条件逻辑
          notes: string; // 规则备注
  }

// 报警规则 API
export const AlertRulesApi = {
  // 查询报警规则分页
  getAlertRulesPage: async (params: any) => {
    return await request.get({ url: `/business/alert-rules/page`, params })
  },

  // 查询报警规则详情
  getAlertRules: async (id: number) => {
    return await request.get({ url: `/business/alert-rules/get?id=` + id })
  },

  // 新增报警规则
  createAlertRules: async (data: AlertRules) => {
    return await request.post({ url: `/business/alert-rules/create`, data })
  },

  // 修改报警规则
  updateAlertRules: async (data: AlertRules) => {
    return await request.put({ url: `/business/alert-rules/update`, data })
  },

  // 删除报警规则
  deleteAlertRules: async (id: number) => {
    return await request.delete({ url: `/business/alert-rules/delete?id=` + id })
  },

  /** 批量删除报警规则 */
  deleteAlertRulesList: async (ids: number[]) => {
    return await request.delete({ url: `/business/alert-rules/delete-list?ids=${ids.join(',')}` })
  },

  // 导出报警规则 Excel
  exportAlertRules: async (params) => {
    return await request.download({ url: `/business/alert-rules/export-excel`, params })
  },
}